
import unittest
import gamestate
import randomplayer

class  GameStateTest(unittest.TestCase):

    def setUp(self):
        self.__player_list = []
        self.__player_list.append(randomplayer.RandomPlayer())
        self.__player_list.append(randomplayer.RandomPlayer())

    def test_creation(self):
        try:
            gs = gamestate.GameState([], 4)
            self.fail("Expected exception to occur.")
        except:
            pass

        try:
            gs = gamestate.GameState(self.__player_list, 0)
            self.fail("Expected exception to occur.")
        except:
            pass

        gs = gamestate.GameState(self.__player_list, 2)
        gs = gamestate.GameState(self.__player_list, 4)
        gs = gamestate.GameState(self.__player_list, 6)


    def test_correct_finish(self):
        for i in range(1, 5):
            pre_score_list = []

            different = False
            for x in range(100):
                gs = gamestate.GameState(self.__player_list, i * 2)
                p = 10000
                for p in range(1000):
                    gs.next_turn()
                    gs.print_current_state()
                    if gs.is_finished():
                        break
                self.assertTrue(p < 999)
                score_list = gs.get_final_score_list()

                if len(pre_score_list) > 0:
                    for y, score in enumerate(pre_score_list):
                        if score != score_list[y]:
                            different = True

                pre_score_list = score_list
            self.assertTrue(different)


def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(GameStateTest))
    return suite

if __name__ == '__main__':
    unittest.main()
